add _gtk_rbtree_set_fixed_height()
authorKristian Rietveld <kris@gtk.org>
Wed, 20 Mar 2002 22:06:05 +0000 (22:06 +0000)
committerKristian Rietveld <kristian@src.gnome.org>
Wed, 20 Mar 2002 22:06:05 +0000 (22:06 +0000)
Wed Mar 20 22:59:23 2002  Kristian Rietveld  <kris@gtk.org>

        * gtk/gtkrbtree.[ch]: add _gtk_rbtree_set_fixed_height()

        * gtk/gtktreeprivate.h: add fixed_height_check field

        * gtk/gtktreeview.c (gtk_tree_view_init): initialize
        scroll_sync_timer and fixed_height_check
        (do_validate_rows): add fixed_height_check. If all validated rows
        in the first cycle have the same height, then we set that height for
        the entire tree. This is some sort of 'fake' optimization, but helps
        a lot for the common case. We keep validating the entire tree in
        the background though.
        (gtk_tree_view_set_model): reset fixed_height_check

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkrbtree.c
gtk/gtkrbtree.h
gtk/gtktreeprivate.h
gtk/gtktreeview.c

index b4d61c84705b99f74b36e09879f8bc54967864be..d283f275df1c0b7cf65638447065238a14afa9e9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+Wed Mar 20 22:59:23 2002  Kristian Rietveld  <kris@gtk.org>
+
+       * gtk/gtkrbtree.[ch]: add _gtk_rbtree_set_fixed_height()
+
+       * gtk/gtktreeprivate.h: add fixed_height_check field
+
+       * gtk/gtktreeview.c (gtk_tree_view_init): initialize
+       scroll_sync_timer and fixed_height_check
+       (do_validate_rows): add fixed_height_check. If all validated rows
+       in the first cycle have the same height, then we set that height for
+       the entire tree. This is some sort of 'fake' optimization, but helps
+       a lot for the common case. We keep validating the entire tree in
+       the background though.
+       (gtk_tree_view_set_model): reset fixed_height_check
+
 Wed Mar 20 16:36:08 2002  Owen Taylor  <otaylor@redhat.com>
 
         * gtk/*.c: Patch from Erwann Chenede, #73900 fixing
index b4d61c84705b99f74b36e09879f8bc54967864be..d283f275df1c0b7cf65638447065238a14afa9e9 100644 (file)
@@ -1,3 +1,18 @@
+Wed Mar 20 22:59:23 2002  Kristian Rietveld  <kris@gtk.org>
+
+       * gtk/gtkrbtree.[ch]: add _gtk_rbtree_set_fixed_height()
+
+       * gtk/gtktreeprivate.h: add fixed_height_check field
+
+       * gtk/gtktreeview.c (gtk_tree_view_init): initialize
+       scroll_sync_timer and fixed_height_check
+       (do_validate_rows): add fixed_height_check. If all validated rows
+       in the first cycle have the same height, then we set that height for
+       the entire tree. This is some sort of 'fake' optimization, but helps
+       a lot for the common case. We keep validating the entire tree in
+       the background though.
+       (gtk_tree_view_set_model): reset fixed_height_check
+
 Wed Mar 20 16:36:08 2002  Owen Taylor  <otaylor@redhat.com>
 
         * gtk/*.c: Patch from Erwann Chenede, #73900 fixing
index b4d61c84705b99f74b36e09879f8bc54967864be..d283f275df1c0b7cf65638447065238a14afa9e9 100644 (file)
@@ -1,3 +1,18 @@
+Wed Mar 20 22:59:23 2002  Kristian Rietveld  <kris@gtk.org>
+
+       * gtk/gtkrbtree.[ch]: add _gtk_rbtree_set_fixed_height()
+
+       * gtk/gtktreeprivate.h: add fixed_height_check field
+
+       * gtk/gtktreeview.c (gtk_tree_view_init): initialize
+       scroll_sync_timer and fixed_height_check
+       (do_validate_rows): add fixed_height_check. If all validated rows
+       in the first cycle have the same height, then we set that height for
+       the entire tree. This is some sort of 'fake' optimization, but helps
+       a lot for the common case. We keep validating the entire tree in
+       the background though.
+       (gtk_tree_view_set_model): reset fixed_height_check
+
 Wed Mar 20 16:36:08 2002  Owen Taylor  <otaylor@redhat.com>
 
         * gtk/*.c: Patch from Erwann Chenede, #73900 fixing
index b4d61c84705b99f74b36e09879f8bc54967864be..d283f275df1c0b7cf65638447065238a14afa9e9 100644 (file)
@@ -1,3 +1,18 @@
+Wed Mar 20 22:59:23 2002  Kristian Rietveld  <kris@gtk.org>
+
+       * gtk/gtkrbtree.[ch]: add _gtk_rbtree_set_fixed_height()
+
+       * gtk/gtktreeprivate.h: add fixed_height_check field
+
+       * gtk/gtktreeview.c (gtk_tree_view_init): initialize
+       scroll_sync_timer and fixed_height_check
+       (do_validate_rows): add fixed_height_check. If all validated rows
+       in the first cycle have the same height, then we set that height for
+       the entire tree. This is some sort of 'fake' optimization, but helps
+       a lot for the common case. We keep validating the entire tree in
+       the background though.
+       (gtk_tree_view_set_model): reset fixed_height_check
+
 Wed Mar 20 16:36:08 2002  Owen Taylor  <otaylor@redhat.com>
 
         * gtk/*.c: Patch from Erwann Chenede, #73900 fixing
index b4d61c84705b99f74b36e09879f8bc54967864be..d283f275df1c0b7cf65638447065238a14afa9e9 100644 (file)
@@ -1,3 +1,18 @@
+Wed Mar 20 22:59:23 2002  Kristian Rietveld  <kris@gtk.org>
+
+       * gtk/gtkrbtree.[ch]: add _gtk_rbtree_set_fixed_height()
+
+       * gtk/gtktreeprivate.h: add fixed_height_check field
+
+       * gtk/gtktreeview.c (gtk_tree_view_init): initialize
+       scroll_sync_timer and fixed_height_check
+       (do_validate_rows): add fixed_height_check. If all validated rows
+       in the first cycle have the same height, then we set that height for
+       the entire tree. This is some sort of 'fake' optimization, but helps
+       a lot for the common case. We keep validating the entire tree in
+       the background though.
+       (gtk_tree_view_set_model): reset fixed_height_check
+
 Wed Mar 20 16:36:08 2002  Owen Taylor  <otaylor@redhat.com>
 
         * gtk/*.c: Patch from Erwann Chenede, #73900 fixing
index b4d61c84705b99f74b36e09879f8bc54967864be..d283f275df1c0b7cf65638447065238a14afa9e9 100644 (file)
@@ -1,3 +1,18 @@
+Wed Mar 20 22:59:23 2002  Kristian Rietveld  <kris@gtk.org>
+
+       * gtk/gtkrbtree.[ch]: add _gtk_rbtree_set_fixed_height()
+
+       * gtk/gtktreeprivate.h: add fixed_height_check field
+
+       * gtk/gtktreeview.c (gtk_tree_view_init): initialize
+       scroll_sync_timer and fixed_height_check
+       (do_validate_rows): add fixed_height_check. If all validated rows
+       in the first cycle have the same height, then we set that height for
+       the entire tree. This is some sort of 'fake' optimization, but helps
+       a lot for the common case. We keep validating the entire tree in
+       the background though.
+       (gtk_tree_view_set_model): reset fixed_height_check
+
 Wed Mar 20 16:36:08 2002  Owen Taylor  <otaylor@redhat.com>
 
         * gtk/*.c: Patch from Erwann Chenede, #73900 fixing
index 0170f2cff19b69c857bc70b1bf315255f9a2f7a4..6810183fcb1c7f04a9cf62b0a3a5bea86bf968a0 100644 (file)
@@ -877,6 +877,32 @@ _gtk_rbtree_mark_invalid (GtkRBTree *tree)
   while ((node = _gtk_rbtree_next (tree, node)) != NULL);
 }
 
+void
+_gtk_rbtree_set_fixed_height (GtkRBTree *tree,
+                             gint       height)
+{
+  GtkRBNode *node;
+
+  if (tree == NULL)
+    return;
+
+  node = tree->root;
+  g_assert (node);
+
+  while (node->left != tree->nil)
+    node = node->left;
+
+  do
+    {
+      if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_INVALID))
+       _gtk_rbtree_node_set_height (tree, node, height);
+
+      if (node->children)
+       _gtk_rbtree_set_fixed_height (node->children, height);
+    }
+  while ((node = _gtk_rbtree_next (tree, node)) != NULL);
+}
+
 typedef struct _GtkRBReorder
 {
   GtkRBTree *children;
index f3c585b8527a68c9a449171bec8b35ed2d63d397..c5b4768db6c4a222595f89db777e84cd6e367399 100644 (file)
@@ -140,6 +140,8 @@ void       _gtk_rbtree_node_mark_valid  (GtkRBTree              *tree,
                                         GtkRBNode              *node);
 void       _gtk_rbtree_column_invalid   (GtkRBTree              *tree);
 void       _gtk_rbtree_mark_invalid     (GtkRBTree              *tree);
+void       _gtk_rbtree_set_fixed_height (GtkRBTree              *tree,
+                                        gint                    height);
 gint       _gtk_rbtree_node_find_offset (GtkRBTree              *tree,
                                         GtkRBNode              *node);
 gint       _gtk_rbtree_node_find_parity (GtkRBTree              *tree,
index 75c84db2b12b03d40efe59bf2ac6df7252b03ddc..7fcaa903a04dc2def811e42fab1ae303e2f34f3b 100644 (file)
@@ -176,6 +176,8 @@ struct _GtkTreeViewPrivate
   gfloat scroll_to_col_align;
   guint scroll_to_use_align : 1;
 
+  guint fixed_height_check : 1;
+
   guint reorderable : 1;
   guint header_has_focus : 1;
   guint drag_column_window_state : 3;
index ec51a0b05e10f506e37acfbb9a962e1243ff763b..955342f1159d63669b0d9b9a0ca40dd3d638d4b3 100644 (file)
@@ -928,6 +928,8 @@ gtk_tree_view_init (GtkTreeView *tree_view)
   tree_view->priv->press_start_y = -1;
   tree_view->priv->reorderable = FALSE;
   tree_view->priv->presize_handler_timer = 0;
+  tree_view->priv->scroll_sync_timer = 0;
+  tree_view->priv->fixed_height_check = 0;
   gtk_tree_view_set_adjustments (tree_view, NULL, NULL);
   tree_view->priv->selection = _gtk_tree_selection_new_with_tree_view (tree_view);
   tree_view->priv->enable_search = TRUE;
@@ -3910,6 +3912,10 @@ do_validate_rows (GtkTreeView *tree_view)
   GtkTreePath *path = NULL;
   GtkTreeIter iter;
   gint i = 0;
+
+  gint prev_height = -1;
+  gboolean fixed_height = TRUE;
+
   g_assert (tree_view);
 
   if (tree_view->priv->tree == NULL)
@@ -3919,7 +3925,6 @@ do_validate_rows (GtkTreeView *tree_view)
     }
   do
     {
-
       if (! GTK_RBNODE_FLAG_SET (tree_view->priv->tree->root, GTK_RBNODE_DESCENDANTS_INVALID))
        {
          retval = FALSE;
@@ -3979,9 +3984,29 @@ do_validate_rows (GtkTreeView *tree_view)
          gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
        }
       validated_area = validate_row (tree_view, tree, node, &iter, path) | validated_area;
+
+      if (!tree_view->priv->fixed_height_check)
+        {
+         gint height;
+
+         height = MAX (GTK_RBNODE_GET_HEIGHT (node), tree_view->priv->expander_size);
+         if (prev_height < 0)
+           prev_height = height;
+         else if (prev_height != height)
+           fixed_height = FALSE;
+       }
+
       i++;
     }
   while (i < GTK_TREE_VIEW_NUM_ROWS_PER_IDLE);
+
+  if (!tree_view->priv->fixed_height_check)
+   {
+     if (fixed_height)
+       _gtk_rbtree_set_fixed_height (tree_view->priv->tree, prev_height);
+
+     tree_view->priv->fixed_height_check = 1;
+   }
   
  done:
   if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
@@ -7455,6 +7480,7 @@ gtk_tree_view_set_model (GtkTreeView  *tree_view,
       g_object_unref (tree_view->priv->model);
       tree_view->priv->search_column = -1;
       GTK_TREE_VIEW_SET_FLAG (tree_view, GTK_TREE_VIEW_IS_LIST);
+      tree_view->priv->fixed_height_check = 0;
     }
 
   tree_view->priv->model = model;